﻿//-----------------------------------------------------------------------
// <copyright file="CustomPagination.aspx.cs" company="CMSN Software">
//    Copyright © 2011  CMSN Software
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see http://www.gnu.org/licenses.
// </copyright>
//-----------------------------------------------------------------------

namespace CMSN.Software.Tutorials.HowToUseCustomPagination
{
    using System;
    using System.Data;
    using System.Globalization;

    /// <summary>
    /// Sample page to show pagination functionality
    /// </summary>
    public partial class CustomPagination : System.Web.UI.Page
    {
        /// <summary>
        /// pagination size
        /// </summary>
        private const int PaginationSize = 10;

        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            // set the pagination size (number of records per page).
            this.RepeaterCustomPagination.PaginationSize = PaginationSize;

            // set data source to the pagination control
            this.RepeaterCustomPagination.DataSource = SampleData.SampleDataList((this.RepeaterCustomPagination.CurrentPage - 1) * PaginationSize, this.RepeaterCustomPagination.CurrentPage * PaginationSize);

            // set the repeater control to be paged.
            this.RepeaterCustomPagination.RepeaterControl = PaginatingRepeater;

            // display first and last links. (default false)  
            this.RepeaterCustomPagination.ShowFirstLast = true;

            // selected page style.
            this.RepeaterCustomPagination.SelectedPageCssClass = "selected-page";

            // pagination point style
            this.RepeaterCustomPagination.PaginationPointCssClass = "pagination-point";
            this.RepeaterCustomPagination.TotalRecordCount = SampleData.TemporaryData().Count;

            // navigation links style
            this.RepeaterCustomPagination.NavigationCssClass = "pagination-point";
        }

        /// <summary>
        /// Handles the PreRender event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_PreRender(object sender, EventArgs e)
        {
            // set the pagination status label text.
            this.PaginationDisplayText.Text = "Showing " + RepeaterCustomPagination.CurrentPageText + " of " + RepeaterCustomPagination.Count;
        }
    }
}